package com.mbcn.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.mbcn.dao.ItemDAO;
import com.mbcn.dao.impl.ItemDAOImpl;
import com.mbcn.model.Item;
import com.mbcn.system.commonUtil.BaseUserAction;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class ItemAction extends BaseUserAction {

	Item item = new Item();
	List<Item> itemList = new ArrayList<Item>();

	public List<Item> getItemList() {
		return itemList;
	}

	public void setItemList(List<Item> itemList) {
		this.itemList = itemList;
	}

	ItemDAO itemsDAO = new ItemDAOImpl();

	public String execute() throws Exception {
		return SUCCESS;
	}

	public Object getModel() {
		return item;
	}

	public String listItemByCategory() throws Exception {
		try {
			itemList = itemsDAO.listItemByCategory(item.getItemCategory());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;

	}

	public String addItem() throws Exception {
		try {
			//Input dataTmp
			item.setMemberId(Integer.parseInt(session.get("memberId").toString()));
			item.setItemStatus(1);// Status 1 is active
			//End input dataTmp
			item.setItemDatePost(new Date());
			itemsDAO.addItem(item);
			
//			//reload the customer list
//			itemList = null;
//			itemList = itemsDAO.listItemByCategory(item.getItemCategory());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;

	}
	
	
	
	

}